/*  
 *  Copyright 2006 Paul Jack.
 *
 *  This file is part of the Dex compiler suite. 
 *  
 *  Dex is free software; you can redistribute it and/or modify it
 *  under the terms of the GNU General Public License as published by the
 *  Free Software Foundation; either version 2 of the License, or (at your
 *  option) any later version.
 *  
 *  Dex is distributed in the hope that it will be useful, but
 *  WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
 *  Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License along
 *  with this program; if not, write to the Free Software Foundation, Inc.,
 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
 */
package dex.test;


import java.io.File;
import java.util.SortedSet;

import junit.framework.AssertionFailedError;


/**
 * Tests that Dex template source files are available for a specific 
 * set of tests.
 */
class CoverageTester extends SingleTest {


	/**
	 * The directory in which to look for template source files.
	 */
	final private File dir;

	
	/**
	 * The set of expected test names.
	 */
	final private SortedSet<String> expected;


	/**
	 * Constructs a new <code>CoverageTester</code>.
	 * 
	 * @param dir  the directory in which to look for template source files
	 * @param expected  the set of expected test names
	 */
	public CoverageTester(File dir, SortedSet<String> expected) {
		super("coverage");
		this.dir = dir;
		this.expected = expected;
	}


	/**
	 * Tests that at least one template source code file exists for
	 * each of the expected tests.
	 */
	public void doTest() {
		File[] files = dir.listFiles();
		for (File f: files) {
			if (TemplateSuite.isTest(f.getName())) {
				expected.remove(TemplateSuite.getTestName(f.getName()));
			}
		}
		
		for (String s: expected) {
			System.out.println(s);
		}
		
		if (!expected.isEmpty()) {
			throw new AssertionFailedError("Cases not covered: " + expected);
		}	
	}


}
